package com.dz.file.design.event;

import com.dz.common.constants.CodeDomain;
import com.dz.file.design.FileService;
import com.dz.file.utils.ApplicationContextUtil;
import com.dz.file.utils.MinioUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.InputStream;

/**
 * @ClassName : FileServiceImpl
 * @Description :
 * @Author : ming
 * @Date: 2020-12-01 10:38
 **/
public class ImageFileServiceImpl implements FileService {

    MinioUtil minioUtil= ApplicationContextUtil.getBean(MinioUtil.class);

    @Override
    public String upload(String objectName, InputStream stream) {
        boolean flag = minioUtil.putImage(CodeDomain.IMAGE_BUCKET.value(), objectName, stream);
        if (flag){
            String url = minioUtil.getObjectUrl(CodeDomain.IMAGE_BUCKET.value(), objectName);
            return url;
        }
        return null;
    }
}
